package com.godpaper.as9.commands
{
	import com.adobe.cairngorm.commands.ICommand;
	import com.adobe.cairngorm.control.CairngormEvent;
	import com.godpaper.as9.bussiness.delegates.PhotoDelegate;
	import com.godpaper.as9.constants.UploadInfoList;
	import com.godpaper.as9.events.GetPhotoInfoEvent;
	import com.godpaper.as9.model.PhotoModelLocator;
	
	import mx.rpc.IResponder;

	public class GetPhotoInfoCommand extends CommandBase implements ICommand, IResponder
	{
		private var delegate:PhotoDelegate;
		private var photoModel:PhotoModelLocator = PhotoModelLocator.getInstance();
		private var getPhotoInfoEvent:GetPhotoInfoEvent;
		public function GetPhotoInfoCommand()
		{
			super();
			delegate = new PhotoDelegate(this);
		}
		
		override public function execute(event:CairngormEvent):void
		{
			getPhotoInfoEvent = GetPhotoInfoEvent(event);
			delegate.read(getPhotoInfoEvent.pno);
		}
		
		override public function result(data:Object):void
		{
			if(data.result)
			{
				photoModel.photoInfo.ano = data.result[0].ano;
				photoModel.photoInfo.name = data.result[0].name;
				photoModel.photoInfo.description = data.result[0].description;
				photoModel.photoInfo.pno = data.result[0].pno;
				photoModel.photoInfo.source = data.result[0].source;
				photoModel.photoInfo.tag = data.result[0].tag;
				photoModel.photoInfo.avg_score = data.result[0].avg_score;
				photoModel.photoInfo.upload_time = data.result[0].upload_time;
				photoModel.photoInfo.uploader = data.result[0].uploader;
				photoModel.photoInfo.capcity = data.result[0].capcity;
				
				photoModel.photoInfo.thumbnail = UploadInfoList.UPLOAD_DEST_BASE.
				concat( photoModel.photoInfo.source.split("/")[2],
						"/tn/",
						photoModel.photoInfo.source.split("/")[3]);
	
			}
		}
		
	}
}